home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Add-Ons / MPW / MPW re2c 1.1 / ANNOUNCE < prev    next >
Encoding:
Text File  |  1995-06-01  |  2.9 KB  |  92 lines  |  [TEXT/MPS ]

  1. An alpha version of re2c is now available by anonymous ftp:
  2.  
  3.     ftp://csg.uwaterloo.ca/pub/peter/re2c.0.5.tar.gz
  4.  
  5. re2c is a tool for generating C-based recognizers from regular
  6. expressions.  re2c-based scanners are efficient:  for programming
  7. languages, given similar specifications, an re2c-based scanner is
  8. typically almost twice as fast as a flex-based scanner with little or no
  9. increase in size (possibly a decrease on cisc architectures).  Indeed,
  10. re2c-based scanners are quite competitive with hand-crafted ones.
  11.  
  12. Unlike flex, re2c does not generate complete scanners:  the user must
  13. supply some interface code.  While this code is not bulky (about 50-100
  14. lines for a flex-like scanner; see the man page and examples in the
  15. distribution) careful coding is required for efficiency (and
  16. correctness).  One advantage of this arrangement is that the generated
  17. code is not tied to any particular input model.  For example, re2c
  18. generated code can be used to scan data from a null-byte terminated
  19. buffer as illustrated below.
  20.  
  21. Given the following source
  22.  
  23.     #define NULL            ((char*) 0)
  24.     char *scan(char *p){
  25.     char *q;
  26.     #define YYCTYPE         char
  27.     #define YYCURSOR        p
  28.     #define YYLIMIT         p
  29.     #define YYMARKER        q
  30.     #define YYFILL(n)
  31.     /*!re2c
  32.         [0-9]+          {return YYCURSOR;}
  33.         [\000-\377]     {return NULL;}
  34.     */
  35.     }
  36.  
  37. re2c will generate
  38.  
  39.     /* Generated by re2c on Sat Apr 16 11:40:58 1994 */
  40.     #line 1 "simple.re"
  41.     #define NULL            ((char*) 0)
  42.     char *scan(char *p){
  43.     char *q;
  44.     #define YYCTYPE         char
  45.     #define YYCURSOR        p
  46.     #define YYLIMIT         p
  47.     #define YYMARKER        q
  48.     #define YYFILL(n)
  49.     {
  50.         YYCTYPE yych;
  51.         unsigned int yyaccept;
  52.         goto yy0;
  53.     yy1:    ++YYCURSOR;
  54.     yy0:
  55.         if((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
  56.         yych = *YYCURSOR;
  57.         if(yych <= '/') goto yy4;
  58.         if(yych >= ':') goto yy4;
  59.     yy2:    yych = *++YYCURSOR;
  60.         goto yy7;
  61.     yy3:
  62.     #line 10
  63.         {return YYCURSOR;}
  64.     yy4:    yych = *++YYCURSOR;
  65.     yy5:
  66.     #line 11
  67.         {return NULL;}
  68.     yy6:    ++YYCURSOR;
  69.         if(YYLIMIT == YYCURSOR) YYFILL(1);
  70.         yych = *YYCURSOR;
  71.     yy7:    if(yych <= '/') goto yy3;
  72.         if(yych <= '9') goto yy6;
  73.         goto yy3;
  74.     }
  75.     #line 12
  76.  
  77.     }
  78.  
  79. Note that most compilers will perform dead-code elimiation to remove
  80. all YYCURSOR, YYLIMIT comparisions.
  81.  
  82. re2c was developed for a particular project (constructing a fast REXX
  83. scanner of all things!) and so while it has some rough edges, it should
  84. be quite usable.  More information about re2c can be found in the
  85. (admittedly skimpy) man page; the algorithms and heuristics used are
  86. described in an upcoming LOPLAS article (included in the distribution).
  87. Probably the best way to find out more about re2c is to try the supplied
  88. examples.  re2c is written in C++, and is currently being developed
  89. under Linux using gcc 2.5.8.
  90.  
  91. Peter
  92.